<template>
  <div class="container">
    <el-input v-model="loginForm.cellphone" placeholder="请输入内容"></el-input>
    <el-input v-model="loginForm.password" placeholder="请输入内容"></el-input>
    <el-button type="primary" @click="login">登录</el-button>
    <el-button type="primary" @click="getDevices">获取设备信息</el-button>

  </div>
</template>

<script>
import { userLogin, userDevices } from "@/api/http";
export default {
  data() {
    return {
      loginForm: {
        cellphone: "15010497821",
        password: "Passw0rd",
      },
      deviceList: []
    };
  },
  methods: {
    login() {
      userLogin(this.loginForm).then((res) => {
        console.log(res);
        const dKey = ".SHLWaterWebAPI.Session"
        const dCookie = "CfDJ8NR1TXkSED9LhE89zFQsuJJzv8eMxRdEAFIIo4Vpk21Scpf41iVxkxQ0MbFHSN3IKVciJQhQrRGcZiYasGakx9GGqmljkpq39ttISAR4%2FrIwvB%2B0d9gtFvVa%2B9Ufv97ktk8AssyxKs2j3Zd%2BDiA7GCcMDW621vkXltrkHWEskigl"
        this.setCookie(dKey, dCookie, 30)
      });
    },
    getDevices() {
      userDevices().then(res => {
        console.log(res)
      })
    },
    setCookie(name,value,timer=1){//默认将被保存 1 天 
      var Days = timer; 
        var exp  = new Date();
        exp.setTime(exp.getTime() + Days*24*60*60*1000);
        document.cookie = name + "="+ value +";expires="+ exp.toGMTString() + ";path=/;domain=api.xiaosuhoyun.cn;";
      }
  },
};
</script>

<style scoped>
.container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
}
</style>
